class Solution {
    public String longestPalindrome(String s) {
        int n=s.length();
        String ret="";
        for(int i=0;i<n;i++){
            int l=i,r=i;
            while(l>=0&&r<n&&s.charAt(l)==s.charAt(r)){
                l--;
                r++;
            }
            if(ret.length()<s.substring(l+1,r).length())
                ret=s.substring(l+1,r);
            l=i-1;
            r=i;
            while(l>=0&&r<n&&s.charAt(l)==s.charAt(r)){
                l--;
                r++;
            }
            if(ret.length()<s.substring(l+1,r).length())
                ret=s.substring(l+1,r);
        }   
        return ret;     
    }
}